ARRAY INSERT AT TOP
This command will insert a blank item at the start of the array list.
ARRAY INSERT AT TOP Array Name(0)
ARRAY INSERT AT TOP Array Name(0), Index
Array Name(0
Integer
The name of the array followed by a pair of brackets ( ). You can also insert a value of zero, i.e. arrayname(0)
Index
Integer
This value is an integer number such as 1.
This command does not return a value.
When a blank item is inserted into a list, all the elements thereafter are shuffled one space down to make room for the new item. Lists are an expandable and shrinkable form of array, and do not use a fixed size.
dim a() as integer
empty array a()
print "Add 5 items to the list"
for i=1 to 5
n = rnd(1000)
print " Adding "; n; " to the list"
array insert at bottom a()
a() = n
next i
print
PrintList()
print
print "Run through the list forwards"
array index to top a()
while array index valid( a() )
print a()
next array index a()
endwhile
print
print "Run through the list backwards"
array index to bottom a()
while array index valid( a() )
print a()
previous array index a()
endwhile
print
print "Step forward to the third item and delete it"
array index to top a()
next array index a()
next array index a()
array delete element a()
PrintList()
print
print "Now insert 3 new random numbers at the top of the list"
for i=1 to 3
n = rnd(1000)
print " Adding "; n; " to the list"
array insert at top a()
a() = n
next i
print
PrintList()
print
print "Deleting every item under 500"
array index to top a()
while array index valid( a() )
if a() < 500
array delete element a()
else
next array index a()
endif
endwhile
PrintList()
wait key
end
function PrintList()
if array count( a() ) >= 0
print "The list has "; array count( a() )+1; " items"
for i=0 to array count( a() )
print " Item "; i; " = "; a(i)
next i
else
print "The list is empty"
endif
endfunction
CORE Commands Menu
Index